<template>
	<el-row :gutter="20" id="listarea" style="padding:20px;">
		<el-col :span="24">
			<div class="block mb mt ov" style="margin-bottom:20px;">
				<el-button type="success" icon="plus" @click="add" v-qx="permission.add" style="margin-bottom:20px;">新增员工</el-button>
				<el-select v-model="page.zt" class="ml" @change="getList" v-qx="permission.status">
					<el-option v-for="s in status" :label="s.txt" :value="s.val" :key="s.val">
					</el-option>
				</el-select>
				<el-button type="primary" icon="h-shuaxin1" class="fr ml" @click="refresh">刷新列表</el-button>
				<el-input
					class="fr w300"
					placeholder="搜索员工姓名、员工电话"
					icon="search"
					@keyup.enter.native="getList"
					v-model="page.search"
					:on-icon-click="getList">
				</el-input>
			</div>
			<el-table :data="list" stripe>
				<el-table-column prop="id" label="ID" width="80"></el-table-column>
				<el-table-column prop="name" label="员工姓名"></el-table-column>
				<el-table-column prop="sex" label="员工性别">
					<template scope="scope">
						<i class="el-icon-h-nv1 color-nv" v-if="!scope.row.sex"></i>
						<i class="el-icon-h-nan1 color-nan" v-else></i>
					</template>
				</el-table-column>
				<el-table-column prop="username" label="员工电话"></el-table-column>
				<el-table-column prop="pname" label="所属职位"></el-table-column>
				<el-table-column prop="zname" label="所属职称"></el-table-column>
				<el-table-column prop="ismanage" label="管理层">
					<template scope="scope">
						<el-tag type="success" v-if="scope.row.ismanage"><i class="el-icon-h-shi"></i></el-tag>
						<el-tag type="danger" v-else><i class="el-icon-h-fou"></i></el-tag>
					</template>
				</el-table-column>
				<el-table-column prop="remarks" label="员工描述" :show-overflow-tooltip="true"></el-table-column>
				<el-table-column prop="addtime" label="添加日期">
					<template scope="scope">
						{{time(scope.row.addtime)}}
					</template>
				</el-table-column>
				<el-table-column label="操作" width="100">
                    <template scope="scope">
                        <el-dropdown size="small" trigger="click" @command="moreMenu" v-if="!scope.row.isdisable">
                        <el-button type="primary" size="small">更多操作<i class="el-icon-arrow-down el-icon--right"></i></el-button>
                        <el-dropdown-menu slot="dropdown">
                            <el-dropdown-item :command="{row: scope.row, tp: 1}" v-qx="permission.edit">编辑员工</el-dropdown-item>
                            <el-dropdown-item :command="{id: scope.row.id, tp: 2}" v-qx="permission.reset">重置密码</el-dropdown-item>
                            <el-dropdown-item :command="{id: scope.row.id, st: 1, tp: 3}" v-qx="permission.unstop">员工离职</el-dropdown-item>
                        </el-dropdown-menu>
                        </el-dropdown>
                        <el-tooltip content="复职员工" placement="left" :open-delay="800" v-else v-qx="permission.unstop">
                            <el-button type="success" icon="h-qiyong2" size="small" @click="stop(scope.row.id,0)"></el-button>
                        </el-tooltip>
                    </template>
				</el-table-column>
			</el-table>
			<div class="block center bg-light">
				<el-pagination
					@size-change="sizeChange"
					@current-change="currentChange"
					:current-page="page.pages"
					:page-sizes="[15, 30, 50, 100]"
					:page-size="page.limits"
					layout="total, sizes, prev, pager, next, jumper"
					:total="total">
				</el-pagination>
			</div>
		</el-col>
	</el-row>
</template>
<!--<script src="../../../static/js/jquery-1.9.1.min.js"></script>
<script src="../../../static/plugins/adminex/js/jquery.nicescroll.js"></script>
<script src="../../../static/plugins/adminex/js/scripts.js"></script>
<script src="../../../static/plugins/layer/layer.js"></script>
<script src="../../../static/js/H.js"></script>
<script src="../../../static/js/vue.js"></script>
<script src="../../../static/js/element.js"></script>
<script src="../../../static/js/qx.js"></script>-->
<script>
import C from '#/src/common/common.js'
export default {
    name: 'userselectzhiwei',
    data () {
        return {
            list: [],
            total: 0,
            page: {
                pages: 1,
                limits: 15,
                search: '',
                zt: 0,
            },
            status: [{
                txt: '正常',
                val: 0
            }, {
                txt: '停职',
                val: 1
            }],
            permission: {
                add: 'userlist_add',
                status: 'userlist_status',
                edit: 'userlist_edit',
                unstop: 'userlist_unstop',
                reset: 'userlist_reset',
            }
        }
    },
    mounted () {
        this.getList()
    },
    methods: {
        moreMenu (com) {
            // let that = this
            if (com.tp === 1) {
                this.edit(com.row)
            } else if (com.tp === 2) {
                this.resetPassWord(com.id)
            } else if (com.tp === 3) {
                this.stop(com.id, com.st)
            }
        },

        resetPassWord (id) {
            C.confirm('重置当前员工帐号密码为当前手机号，是否继续？', async () => {
                let res = await C.ajax('/organization/user/resetpassword', { id: id })
                if (res) C.success(res.data)
            })
        },

        async add () {
            await C.openBrowserWindow('/userAdduser', {}, { width: 400, height: 540, useSpa: true, spaModel: 'organization', transparent: true, frame: false
            })
            // H.ajaxiframe('user_adduser.html', {}, 400, 540, '新增员工')
        },

        async edit (row) {
            console.log(row)
            // H.ajaxiframe('user_adduser.html', { row: row }, 400, 540, '编辑员工信息')
            await C.openBrowserWindow('/userAdduser', { row: row }, { width: 400, height: 540, useSpa: true, spaModel: 'organization', transparent: true, frame: false
            })
        },

        async stop (id, st) {
            let that = this
            if (st) {
                C.confirm('停用当前员工, 是否继续?', async () => {
                    let res = await C.ajax('/organization/user/unstop', { id: id, st: st }, 'post')
                    if (res) {
                        C.success(res.data)
                        that.getList()
                    }
                })
            } else {
                let res = await C.ajax('/organization/user/unstop', { id: id, st: st }, 'post')
                if (res) {
                    C.success(res.data)
                    that.getList()
                }
            }
        },
        refresh () {
            window.location.reload()
        },

        sizeChange (val) {
            this.page.limits = val
            this.getList()
        },

        currentChange (val) {
            this.page.pages = val
            this.getList()
        },

        async getList () {
            let that = this
            let data = await C.ajax('/organization/user/userlist', this.page, 'post')
            if (data) {
                that.list = data.data
                that.total = data.count
            }
        },

        time (unix) {
            return C.time(unix)
        }
    }
}
</script>
<style>
.el-dropdown-menu {
  min-width: 0;
}
.el-dropdown-menu__item {
  font-size: 15px;
  line-height: 30px;
}
</style>